<template>
    <div>
    <h1>显示房号信息</h1>
    </div>
    房号名称:
    <input type="text" v-model="datea.name">
    创建时间:
      <input type="date" v-model="datea.starePteaDate">
  
      <input type="date" v-model="datea.endStarePtea">

<input type="button" value="查询" @click="stete()">
    <table class="table">
     <thead>
         <tr>
            <td>id</td>
            <td>房号名称</td>
            <td>备注</td>
            <td>创建时间</td>
            <td>结束时间</td>
            <td>状态</td>
            <td>操作</td>
         </tr>
     </thead>
       <tbody>
         <tr v-for="a in data">
            <td>{{a.stareId}}</td>
            <td>{{a.starePteaName}}</td>
            <td>{{a.starePteaType}}</td>
            <td>{{moment(a.starePteaDate).format("yyyy-MM-DD")}}</td>
            <td>{{moment(a.endStarePtea).format("yyyy-MM-DD")}}</td>
            <td>{{a.isStarePtea==true?"上架":"下架"}}</td>
            <td>
                <input type="button" value="修改状态" @click="updatee(a.id)">
                    <input type="button" value="删除" @click="deltete(a.id)">
            </td>
         </tr>
     </tbody>
    </table>
</template>

<script setup lang="ts">
  import axios from 'axios';
  import{ref,onMounted} from 'vue';
 import {useRouter} from 'vue-router';
   import moment from 'moment'
   const router=useRouter();
onMounted(()=>{
    ShowStarePtea();
})

    const data=ref([{

         "starePteaName": "101",
    "starePteaType": "可以",
    "starePteaDate": "2020-05-06T00:00:00",
    "starePteaId": 1,
    "isStarePtea": false,
    "stareId": 2,
    "endStarePtea": "2021-05-06T00:00:00"

    }])

  
  const updatee=(ids:any)=>{

     if(confirm("确认要修改状态吗")){

    axios.get("https://localhost:7295/api/StarePtea/ISstate",{params:{id:ids}}).then(res=>{
          if(res.data>0){

               alert("修改状态成功")

               ShowStarePtea();

          }else{

               alert("修改状态失败")
          }
     })
     }
 
  }

  const deltete=(ids:any)=>{
     if(confirm("确认要删除吗")){
     axios.delete("https://localhost:7295/api/StarePtea/Isdelete",{params:{id:ids}}).then(res=>{
         if(res.data>0){
            alert("删除成功")
            ShowStarePtea();

         }else{
               alert("删除失败") 
         }
      })
     }
 
  }
 const datea=ref({
     name:"",
     starePteaDate:"",
     endStarePtea:"",
 })
 const stete=()=>{
    ShowStarePtea();

 }

     const ShowStarePtea=()=>{
         
         axios.get("https://localhost:7295/api/StarePtea/ShowStarePtea",{params:datea.value}).then(res=>{
            
             data.value=res.data;

         })
     }
</script>

<style scoped>

</style>